#include "motor.h"

#define MOTOR_GPIO_1 12 // for hispark_pegasus
#define MOTOR_GPIO_2 7 // for hispark_pegasus


uint8_t Motor_Init(void){
    uint8_t result1 = IoTGpioInit(MOTOR_GPIO_1);
    uint8_t result2 = IoTGpioSetDir(MOTOR_GPIO_1, IOT_GPIO_DIR_OUT);
    uint8_t result3 = IoTGpioInit(MOTOR_GPIO_2);
    uint8_t result4 = IoTGpioSetDir(MOTOR_GPIO_2, IOT_GPIO_DIR_OUT);
    if(result1 == IOT_SUCCESS && result2 == IOT_SUCCESS && 
        result3 == IOT_SUCCESS && result4 == IOT_SUCCESS){
        printf("motor init success\n"); 
        return IOT_SUCCESS;
    } else{
        printf("motor init fail\n"); 
         return IOT_FAILURE;
    }
}

uint8_t Motor_Start(void){
    uint8_t result1 = IoTGpioSetOutputVal(MOTOR_GPIO_1, 0);
    uint8_t result2 = IoTGpioSetOutputVal(MOTOR_GPIO_2, 1);
    if(result1 == IOT_SUCCESS && result2 == IOT_SUCCESS){
        printf("motor start success\n"); 
        return IOT_SUCCESS;
    } else{
        printf("motor start fail\n"); 
         return IOT_FAILURE;
    }
}

uint8_t Motor_Stop(void){
    uint8_t result1 = IoTGpioSetOutputVal(MOTOR_GPIO_1, 1);
    uint8_t result2 = IoTGpioSetOutputVal(MOTOR_GPIO_2, 1);
    if(result1 == IOT_SUCCESS && result2 == IOT_SUCCESS){
        printf("motor stop success\n"); 
        return IOT_SUCCESS;
    } else{
        printf("motor stop fail\n"); 
         return IOT_FAILURE;
    }
}
